﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using easysql;
namespace Dal
{
    public class MenuDal:BaseDal<MenuModel>
    {
        public MenuDal()
            : base("tb_menu")
        {
        }


        public List<MenuModel> QueryByUser(UserModel user)
        {
            String roleIds = dh.ExecuteScalar("select roleIds from tb_user where username={0} and password={1}", user.username, user.password) + "";
            if (String.IsNullOrEmpty(roleIds))
            {
                throw new IException("该用户没有被赋予人和角色");
            }

            return dh.QueryBySql<MenuModel>(
                @"select * from tb_menu where id in 
                (select menuId from tb_roleMenu where roleId in ("+roleIds+")) order by sequence,id;");
        }
    }
}
